package com.kjcxlab.avcviewer.player;

import java.util.concurrent.ArrayBlockingQueue;
import com.kjcxlab.avcviewer.video.VideoStreamInfo;
import android.view.Surface;

import com.kjcxlab.avcviewer.audio.AudioDecoder;
import com.kjcxlab.avcviewer.audio.IntegrateAac;
import com.kjcxlab.avcviewer.video.IntegrateH264;
import com.kjcxlab.avcviewer.video.VideoDecoder;

/**
 * @author EFHKKLM Ericsson
 */
public class VideoPlayer {
    private final static int CAPACITY = 240;
    private IntegrateH264 mIntegrateH264 = null;
    private IntegrateAac mIntegrateAac = null;
    private VideoDecoder mVideoDecoder = null;
    private AudioDecoder mAudioDecoder = null;
    private ArrayBlockingQueue<byte[]> videoQueue = null;
    private ArrayBlockingQueue<byte[]> audioQueue = null;

    public VideoPlayer(VideoStreamInfo videoinfo) {

        videoQueue = new ArrayBlockingQueue<byte[]>(CAPACITY);
        audioQueue = new ArrayBlockingQueue<byte[]>(CAPACITY);
        mIntegrateH264 = new IntegrateH264(videoinfo.getLocalPort(), videoQueue);
        mIntegrateAac = new IntegrateAac(videoinfo.getLocalPort() + 4, audioQueue);
        mVideoDecoder = new VideoDecoder(videoQueue);
        mVideoDecoder.initDecoder(videoinfo);
        mAudioDecoder = new AudioDecoder(audioQueue);
        mAudioDecoder.init();

    }

    public void startPlay() {
        mIntegrateH264.start();
        mIntegrateAac.start();
        new Thread(mVideoDecoder).start();
        new Thread(mAudioDecoder).start();
    }
}
